<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{    
    /**
     * Initialiseer jQuery View Helper
     */
    protected function _initJQueryViewHelper()
    {
        $view = $this->_getView();
        $view->addHelperPath('ZendX/JQuery/View/Helper', 'ZendX_JQuery_View_Helper');
        $view->jQuery()->setVersion('1.7')       // standaard 1.3.2
                       ->setUiVersion('1.8.16'); // standaard 1.7.1
    }
    
    
    protected function _initViewHelpers()
    {
        $this->bootstrap('layout');
        $layout = $this->getResource('layout');

        $view = $layout->getView();
        $view->doctype('HTML5'); // http://framework.zend.com/manual/en/zend.view.helpers.html#zend.view.helpers.initial.doctype
        $view->headMeta()->appendHttpEquiv('Content-Type', 'text/html;charset=utf-8');
        $view->headTitle('Safti-Kado')->setSeparator(' - ');              
        $view->userline = $this->_getUserLine();
        $view->bigLock = $this->_getLock();
        //$view->addHelperPath("ZendX/JQuery/View/Helper", "ZendX_JQuery_View_Helper");
    }
    
    /**
     * Initialiseer de Navigation View Helper
     */
    protected function _initNavigationViewHelper()
    {
        /**
         * @todo Gebruik database i.p.v. XML.
         */
        $xml = APPLICATION_PATH . '/configs/navigation.xml';
        $pages = new Zend_Config_Xml($xml);
        $navigation = new Zend_Navigation($pages);
        //$storage = Zend_Auth::getInstance()->getStorage()->read();
        //$role = (isset ($storage->Role) ) ?  $storage->Role : 'guest';
        //$role = (isset ($storage[role]) ) ?  $storage[role] : 'guest';
        //Zend_Debug::dump($storage[role]);
        
        $view = $this->_getView();
        $view->navigation($navigation);
             //->setAcl( new Ahs_Acl() )
             //->setRole($role);            
    }
    
    protected function _initBaseUrl()
    {
        $this->bootstrap("frontController");
        $front=$this->getResource("frontController");
        $request=new Zend_Controller_Request_Http();
        $front->setRequest($request);
    }
    
    protected function _getUserLine()
    {
        // Base url
        $this->_initBaseUrl();
        $base_url           = Zend_Controller_Front::getInstance()->getBaseUrl();
        
        // Check for an active session
        if(Zend_Auth::getInstance()->hasIdentity())
        {
            // Get storage
            $storage            = Zend_Auth::getInstance()->getStorage()->read();            
            return '<div id="lock" class="unlocked">locked or not</div>' . 'Welkom, ' . $storage->user_givenname .' ' . '<a id="logout" href="' .$base_url. '/user/logout">Afmelden</a>';
            
            
        }
        else
        {            
            return '<div id="lock" class="locked">locked or not</div><a href="' . $base_url . '">Aanmelden</a>';
        }
    }
    
    protected function _getLock()
    {
        // Check for an active session
        if(Zend_Auth::getInstance()->hasIdentity())
        {

            return 'big-lock-unlocked';            
        }
        else
        {
            return 'big-lock-locked';            
        }
    }
        
     /**
     * @param string $resource
     * @return Zend_View
     */
    protected function _getView($resource = 'layout')
    {
        $this->bootstrap($resource);
        $layout = $this->getResource($resource);
        $view = $layout->getView();

        return $view;
    }

}
